<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        .box {
            width: 600px;
            height: 350px;
            border: 10px solid pink;
            margin: 30px auto;
            display: flex;
            flex-direction: column;
        }
        
        .box>ul {
            height: 80px;
            display: flex;
        }
        
        .box>ul>li {
            flex: 1;
            background-color: aqua;
            color: aliceblue;
            font-size: 34px;
            display: flex;
            justify-content: center;
            align-items: center;
            cursor: pointer;
        }
        
        .box>ol {
            flex: 1;
            position: relative;
        }
        
        .box>ol>li {
            width: 100%;
            height: 100%;
            position: absolute;
            left: 0;
            top: 0;
            display: none;
            justify-content: center;
            align-items: center;
            background-color: blueviolet;
            color: aliceblue;
            font-size: 100px;
        }
        
        .box>ul>li.active {
            background-color: orange;
        }
        
        .box>ol>li.active {
            display: flex;
        }
    </style>
    <div class="box" id="box1">
        <ul>
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
        </ul>
        <ol>
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
        </ol>
    </div>
    <div class="box" id="box2">
        <ul>
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
        </ul>
        <ol>
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
        </ol>
    </div>

    <script>
        //   '#box2',   'mousemove' 无则click 有则改成所写事件 例如 mousemove
        function Tabs(select, type = 'click') {
            // 通过传入id（select）获取元素 
            this.ele = document.querySelector(select);
            // 通过querySelectorAll方法获取伪数组lis
            this.lis = this.ele.querySelectorAll('ul>li');
            // 通过querySelectorAll方法获取伪数组boxs
            this.boxs = this.ele.querySelectorAll('ol>li');
            // 添加事件
            this.type = type
                // Tabs调用操作方法init
            this.init()
        }

        // 给实例化对象添加操作方法
        Tabs.prototype.init = function() {
                //  lis进行遍历
                this.lis.forEach((ele, index) => {
                    // 每个元素添加事件
                    ele.addEventListener(this.type, () => {
                        for (let i = 0; i < this.lis.length; i++) {
                            // lis所有元素类名改为空
                            this.lis[i].className = '';
                            this.boxs[i].className = '';
                        }
                        // 通过index 对应lis boxs元素类名改为 active
                        this.lis[index].className = 'active'
                        this.boxs[index].className = 'active'
                    })
                })
            }
            // const a = 
            // 构造函数 传参 '#box1'
        new Tabs('#box1');
        // 构造函数 传参 '#box2', 'mousemove'
        new Tabs('#box2', 'mousemove');
        // a.init();
        // console.log(a);
    </script>
</body>

</html>